﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AutoEditUI
{
    /// <summary>
    /// Conf.xaml 的交互逻辑
    /// </summary>
    public partial class Conf : Window
    {
        public ObservableCollection<ItemMES> ObservableObj;
        public Conf()
        {
            InitializeComponent();
            ObservableObj = new ObservableCollection<ItemMES>();
            //ObservableObj.Add(new { Name = "帅波", Sex = "男", Age = 20 });
            lv.DataContext = ObservableObj;
            gAPPModel = (APPModel)XmlSerializer.LoadFromXml(MainWindow.gNowPath + "MES.xml", typeof(APPModel));
            RefreshItemMESs();
        }

        public APPModel gAPPModel { get; private set; }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ItemMES mitem = new ItemMES() {
            Value= TextBoxMES
            .Text};

            gAPPModel.ItemMESs.Add(mitem);
            RefreshItemMESs();
        }

        private void RefreshItemMESs()
        {
            ObservableObj.Clear();
            foreach (ItemMES item in gAPPModel.ItemMESs)
            {
                ObservableObj.Add(item);
            }
        }

        private void Del_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            XmlSerializer.SaveToXml(MainWindow.gNowPath + "MES.xml", gAPPModel, null, null);
        }
    }
}
